<?php
defined('SYSPATH') OR die('No Direct Script Access');
session_name('curriculo');
session_start();
session_unset();

include "application/classes/validator/ValidadorDeLogin.php";
include "application/classes/model/persistencia/CandidatoLoginLoader.php";

Class Controller_Login extends Controller_TemplatePadrao
{

	public $errors = array();
	public $camposDoFormulario;
	public $sheets = array('reset' => 'screen', 'main' => 'screen');
	public $paginaLogin;
	
	function action_index(){
		$this->carregarFormulario();
		
	}
	
	public function carregarFormulario(){
		$ko3_inner               = array();
		$ko3                     = array();
		$this->template->title   = 'Psicopuc WWW Ver. 3.0';
		View::set_global('x', 'Esta e uma variavel global');
		$ko3_inner['content']    = 'Dados(Exemplo)';
		$ko3['content']          = 'Dados2(Exemplo)';
		$this->template->header  = View::factory('blocks/pagina_header', $ko3_inner)
	                              ->render();
	    $this->template->menu    = View::factory('blocks/menu_login')
	    						  ->render();
	    $this->template->footer  = View::factory('blocks/pagina_footer')
	                              ->render();						  
	    $this->template->content = View::factory('Formularios/PaginaLogin', $ko3)		
	    ->bind('errors', $this->errors)
	    ->bind('camposDoFormulario', $this->camposDoFormulario)                     
		->bind('paginaLogin', $this->paginaLogin);
	}


	public function action_validarUsuario(){
		$_SESSION['pagina_corrente'] = "candidato";
		$acao = "";
		
		if(isset($_POST['acao'])){
			$acao = $_POST['acao'];
		}
		
		echo "ACAO = " . $acao;
		if(isset($_POST['email'])){
			echo "<br> EMAIL = " . $_POST['email'];
		}
		else{
			echo "<br> FERRO MAIL";
			
		}
		
	if(isset($_POST['rg'])){
			echo "<br> RG = " . $_POST['rg'];
		}
		else{
			echo "<br> FERRO RG";
			
		}
		
		if($acao == "Cadastrar"){
			$_SESSION['login'] = "PsicoPuc";
			$_SESSION['status'] = "REGISTER";	
			echo "<meta http-equiv=Refresh content=0;url=".url::site()."GerenciadorDeCandidato>";
		}
		else if($acao == "Entrar"){
			$email = $_POST['email'];
			$rg = $_POST['rg'];
			$_SESSION['login'] = "PsicoPuc";
			$_SESSION['status'] = "UPDATE";
			$candidatoLoginLoader = new CandidatoLoginLoader();
			$candidatoLoginLoader->loginCandidato($email, $rg);
			
			echo "<meta http-equiv=Refresh content=0;url=".url::site()."GerenciadorDeCandidato>";
		}
		else{
			echo"Algo misterioso ocorreu!";	
			//echo "<meta http-equiv=Refresh content=0;url=".url::site()."GerenciadorDeCandidato>";
		}

		/*$validator = new ValidadorDeLogin();
		$validator->verificarLogin();
		
	

		if(!$validator->isFormularioValido()){
			$this->errors = $validator->getErros();				
			$this->carregarFormulario();			

		}
		else{			
			$_SESSION['login'] = "PsicoPuc";		
			echo "<meta http-equiv=Refresh content=0;url=".url::site()."GerenciadorDeCandidato>";
			
		}*/


	}
	

}

?>
